package day4;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public
class TestConstructor {
    public static
    void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //1.获取类对象
        Class c=Class.forName("day4.Per");
        //2.(1)利用类对象的newInstance()方法创建对象   底层调用无参构造器
        //Per per = (Per) c.newInstance();
        //System.out.println(per);
        //  (2)利用类对象的getConstructor(参数类型.class)方法获取构造器对象 再利用构造器对象的newInstance(参数)方法创建对象
        Constructor co=c.getDeclaredConstructor();
        Constructor co1=c.getDeclaredConstructor(Integer.class);
        co.setAccessible(true);
        Per per = (Per) co.newInstance();
        Per per1 = (Per) co1.newInstance(10);
        System.out.println(per);
        System.out.println(per1);
    }
}
